const imagemin = require('imagemin');
const imageminJpegtran = require('imagemin-jpegtran');
const imageminPngquant = require('imagemin-pngquant');

const SearchDirectory = require("./SearchDirectoryJpgPng")

const path = require('path')


const compressPath = process.argv[2]

const outputPath = process.argv[3]

if (!compressPath) {
    console.warn("compressPath not exist=", compressPath)
    return
}

if (!outputPath) {
    console.warn("outputPath  not exist=", outputPath)
    return
}
console.info("compressPath =", compressPath)
console.info("outputPath =", outputPath)

let minArr =  SearchDirectory.getAllDirectory(compressPath);

let minPathList = minArr[0]
let minPathFileList = minArr[1]
console.log("minPathList=", minPathList)
console.log("minPathFileList=", minPathFileList)


for (let i = 0; i < minPathFileList.length; i++) {
    (async () => {
        let tempOut = path.join(outputPath, minPathList[i])
        console.log("tempOut===", tempOut)
        imagemin([minPathFileList[i]], {
            destination: tempOut,
            plugins: [
                imageminJpegtran(),
                imageminPngquant({
                    quality: [0.6, 0.8]
                })
            ],
            glob: false
        });
    })();
}


